import time
import functools


def deco_retry(retry: int = 5, retry_sleep: int = 3):
    """
    :param retry: 重试次数
    :param retry_sleep: 重试之间间隔时间（单位为秒）
    :return:
    """
    def deco_func(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            _retry = 5 if callable(retry) else retry
            _result = None
            for _i in range(1, _retry + 1):
                try:
                    # print(f'进行第{_i}次尝试')
                    _result = func(*args, **kwargs)
                    break
                except Exception as e:
                    if _i == _retry:
                        raise
                time.sleep(retry_sleep)
            return _result

        return wrapper

    return deco_func(retry) if callable(retry) else deco_func


if __name__ == '__main__':
    pass
